import request from '@/utils/request'
import type {
  depAllApi,
  uploadImgApi,
  patientConsultOrderPreReq,
  patientConsultOrderPreApi,
  patientInfoApi,
  patientConsultOrderReq,
  patientConsultPayReq
} from '@/types/consult'

// 获取所有科室
export const depAll = () => {
  return request<depAllApi>('/dep/all')
}

// 上传图片
export const uploadImg = (file: File) => {
  // 文件对象就是File类型
  // 将file转换成formdata
  const t = new FormData()
  t.append('file', file)
  return request<uploadImgApi>('/upload', 'post', t)
}

// 获取支付详情
export const patientConsultOrderPre = (data: patientConsultOrderPreReq) => {
  return request<patientConsultOrderPreApi>('/patient/consult/order/pre', 'get', data)
}

// 获取患者详情
export const patientInfo = (id: string) => {
  return request<patientInfoApi>(`/patient/info/${id}`)
}

// 创建问诊订单
export const patientConsultOrder = (data: patientConsultOrderReq) => {
  return request<{
    id: string
  }>('/patient/consult/order', 'post', data)
}

// 支付接口调用
export const patientConsultPay = (data: patientConsultPayReq) => {
  return request<{
    payUrl: string
  }>('/patient/consult/pay', 'post', data)
}
